import 'package:flutter_xiaomi/app/modules/address/services/address_service.dart';
import 'package:flutter_xiaomi/app/modules/address/services/address_service2.dart';
import 'package:get/get.dart';

class AddressController extends GetxController {
  //TODO: Implement AddressController

  ///如何在controller使用:引用的方式：避免其他通知的介入：对复杂业务进行抽离处理
  final AddressService _myService = Get.put(AddressService(),tag: "ser");
  final AddressService2 _myService2 = Get.find<AddressService2>();

  final controllerData = "".obs;

  @override
  void onInit() {
    super.onInit();
    // 在Controller初始化时监听Service中数据的变化
    ever<String>(_myService.data, (newData) {
      ///刷新controller对外的数据
      controllerData.value = newData;
      print("AddressController${controllerData.value}");
    });

    // 在Controller初始化时监听合并后的数据
    ever<String>(_myService2.data, (newData) {
      ///刷新controller对外的数据:数据合并
      print("${_myService.data}+${newData}");
    });

  }

  @override
  void onReady() {
    super.onReady();
  }

  @override
  void onClose() {
    super.onClose();

  }

  void increment() {
    _myService.updateData("new data");
    _myService2.updateData("new data2222");
  }
}
